package com.zqq.user.presenter

import android.util.Log
import com.zqq.baselibrary.ext.excute
import com.zqq.baselibrary.http.rx.BaseSubscriber
import com.zqq.baselibrary.presenter.BasePresenter
import com.zqq.user.presenter.view.RegisterView
import com.zqq.user.service.UserService
import javax.inject.Inject
import javax.inject.Named

/**
 * 用户注册Presenter
 * wc
 * @author zqq on 2018/7/26
 */
class RegisterPresenter @Inject constructor(): BasePresenter<RegisterView>() {

    @Inject
    @field:[Named("service")]
    lateinit var userService: UserService

    //测试限定符---Java中直接@Named("**")
    @Inject
    @field:[Named("service2")]
    lateinit var userService2: UserService

    /**
     * 注册
     */
    fun register(mobile: String, pwd: String, verifyCode: String) {
        if (!checkNetWork()) {
            return
        }
        mView.showLoading()

        userService.register(mobile, pwd, verifyCode)
                .excute(object :BaseSubscriber<Boolean>(mView){
                    override fun onNext(t: Boolean) {
                        super.onNext(t)
                        if (t)
                            mView.onRegisterResult("注册成功")
                    }

                    override fun onError(e: Throwable) {
                        super.onError(e)
                        Log.e("Tag","aaaaaaaaaaaaaaa")
                    }
                },lifecycleProvider)
    }

    //测试限定符
    fun register2() {
        userService2.register("ss","ss","sss")
                .excute(object :BaseSubscriber<Boolean>(mView){
                    override fun onNext(t: Boolean) {
                        super.onNext(t)
                        mView.onRegisterResult("sss")
                    }

                    override fun onError(e: Throwable) {
                        Log.e("Tag","aaaaaaaaaaaaaaa")
                    }
                },lifecycleProvider)
    }

}